package com.feather.tenia.adapter.util;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author flogyin
 */
public class CloseUtil {
	private CloseUtil() {
	}

	public static void close(ResultSet rset) {
		if (rset != null) {
			try {
				rset.close();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		}
	}

	public static void close(Statement stmt) {
		if (stmt != null) {
			try {
				stmt.close();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		}
	}

	public static void close(PreparedStatement pstmt) {
		if (pstmt != null) {
			try {
				pstmt.close();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		}
	}

	public static void close(CallableStatement cstmt) {
		if (cstmt != null) {
			try {
				cstmt.close();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		}
	}

	public static void close(Connection conn) {
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		}
	}

	public static void close(ResultSet rset, Statement stmt, PreparedStatement pstmt, CallableStatement cstmt, Connection conn) {
		close(rset);
		close(stmt);
		close(pstmt);
		close(cstmt);
		close(conn);
	}

	public static void close(ResultSet rset, Statement stmt, PreparedStatement pstmt, Connection conn) {
		close(rset);
		close(stmt);
		close(pstmt);
		close(conn);
	}

	public static void close(ResultSet rset, CallableStatement cstmt, Connection conn) {
		close(rset);
		close(conn);
	}

	public static void close(ResultSet rset, Connection conn) {
		close(rset);
		close(conn);
	}

	public static void close(Statement stmt, Connection conn) {
		close(stmt);
		close(conn);
	}

	public static void close(PreparedStatement pstmt, Connection conn) {
		close(pstmt);
		close(conn);
	}

	public static void close(ResultSet rset, Statement stmt, Connection conn) {
		close(rset);
		close(stmt);
		close(conn);
	}

	public static void close(ResultSet rset, PreparedStatement pstmt, Connection conn) {
		close(rset);
		close(pstmt);
		close(conn);
	}

	/*
	 * public static String getColumnTypeName(ResultSet rset, int column) throws
	 * SQLException { return rset.getMetaData().getColumnTypeName(column); }
	 * public static String getColumnTypeName(ResultSet rset, String column)
	 * throws SQLException { ResultSetMetaData rsMetaData = rset.getMetaData();
	 * return rsMetaData.getColumnTypeName(rset.findColumn(column)); }
	 */
}
